const call = {
    state: {
      callMsg:{       // 用于整合store中mobile,callType,curRecordFile
        telMsg: {},
        leadInMsg:{},
        mobile:'',
        callType:'',
        curRecordFile:'',
        createdTime: null,
        serviceForm:{
          que1:'',
          que2: '',
          content:'',
        }
      },
      callList:{     // 通话详情页面的通话队列
        data:[], // 通话队列
        curIndex: -1  // 指明当前展示的是通话在通话列表中的下标 [空数组时为-1]
      },
      handleStatus:'',
      dialog:{
        isSwitch: false,
        isSubmitGD: false
      },
      seats:[],   // 当前的通话状态信息
      calls:[],   // 当前的通话信息
      queues:[],   // 当前的排队信息
      callInfo:'通话尚未建立连接',
      isHangup:true,   // 表示是否挂机
      daida:null
    },
    getters: {
      callMsg: state => {
        return state.callMsg
      },
      callList: state =>{
        return Object.assign({},state.callList)   // 返回副本，而不是原数组引用
      },
      handleStatus: state => {
        return state.handleStatus
      },
      dialog: state => {
        return state.dialog
      },
      seats: state => {
        // console.log('getters:', state.seats)
        return state.seats
      },
      calls: state => {
        return state.calls
      },
      queues: state => {
        return state.queues
      },
      callInfo: state => {
        return state.callInfo
      },
      isHangup: state => {
        return state.isHangup
      },
      daida: state => {
        return state.daida
      }
    },
    actions: {
      updateCallMsg({state, commit}, callMsg){
        // 在这面
        const tmpo = Object.assign({},state.callMsg)
        let ret
        // 图省事 这里对serviceForm 做2层合并
        if(callMsg.serviceForm){
          // let sf = tmpo.serviceForm
          let ins = Object.assign({},tmpo.serviceForm,callMsg.serviceForm)  // 先对里层做合并
          let ous = Object.assign({},tmpo, callMsg)  // 再对外层做合并
          ous.serviceForm = ins
          ret = ous
        }else{
          ret = Object.assign({}, tmpo, callMsg)
        }
        commit('UPDATECALLMSG', ret)
      },
      updateCallListByIndex({state, commit}, callData){
        const callList = Object.assign({},state.callList)
        const index = callData.curIndex
        const data = Object.assign([],callList.data)
        const curCall = data[index]
        //
        const tmpo = Object.assign({},curCall)
        const callMsg = Object.assign({},callData.callMsg)
        let ret
        // 图省事 这里对serviceForm 做2层合并
        if(callMsg.serviceForm){
          // let sf = tmpo.serviceForm
          let ins = Object.assign({},tmpo.serviceForm,callMsg.serviceForm)  // 先对里层做合并
          let ous = Object.assign({},tmpo,callMsg)  // 再对外层做合并
          ous.serviceForm = ins
          ret = ous
        }else{
          ret = Object.assign({}, tmpo, callMsg)
        }
        data[index] = ret
        callList.data = data
        commit('UPDATECALLLIST',callList)
      },
      updateCallList({state,commit},callList){
        const tmpo = Object.assign({},callList)
        commit('UPDATECALLLIST',tmpo)
      },
      updateHandleStatus({ commit }, handleStatus){
        commit('UPDATEHADNLESTATUS', handleStatus)
      },
      updateDialog({ state, commit }, dialog){
        const tmpo = state.dialog
        const ret = Object.assign({}, tmpo, dialog)
        commit('UPDATEDIALOG', ret)
      },
      updateSeats({ state, commit }, seats){
        // console.log('store seats:', seats)
        commit('UPDATESEATS', seats)
      },
      updateCalls({ state, commit }, calls){
        commit('UPDATECALLS', calls)
      },
      updateQueues({ state, commit }, queues){
        commit('UPDATEQUEUES', queues)
      },
      updateCallInfo({ state, commit }, callInfo){
        commit('UPDATECALLINFO', callInfo)
      },
      updateIsHangup({ state, commit }, isHangup){
        commit('UPDATEISHANGUP', isHangup)
      },
      // 设置待打对象
      updateDaida({state,commit}, daida){
        commit('UPDATEDAIDA', daida)
      }
    },
    mutations: {
      UPDATECALLMSG(state, callMsg){
        window.localStorage.setItem('callMsg', JSON.stringify(callMsg))
        state.callMsg = callMsg
      },
      UPDATECALLLIST(state,callList){
        window.localStorage.setItem('callList', JSON.stringify(callList))
        state.callList = callList
      },
      UPDATEHADNLESTATUS(state, handleStatus){
        state.handleStatus = handleStatus
      },
      UPDATEDIALOG(state, dialog){
        state.dialog = dialog
      },
      UPDATESEATS(state, seats){
        state.seats = seats
      },
      UPDATECALLS(state, calls){
        state.calls = calls
      },
      UPDATEQUEUES(state, queues){
        state.queues = queues
      },
      UPDATECALLINFO(state, callInfo){
        state.callInfo = callInfo
      },
      UPDATEISHANGUP(state, isHangup){
        state.isHangup = isHangup
      },
      // 设置待打对象
      UPDATEDAIDA(state, daida){
        state.daida = daida
      }
    }
  }
  export default call
